require(["common", "jQuery", "coAjax", "queryString", "href", "hash_routie"], function(jSouper, $, coAjax, QueryString, href, hash_routie) {
	var bg_imgs = App.get("bus_loginer.config.bg_imgs");
	if (!bg_imgs) {
		bg_imgs = [];
		App.set("bus_loginer.config.bg_imgs", bg_imgs);
	}

	function _upload_config(cb) {
		coAjax.put(appConfig.bus.set_config_url, {
			mix_data: App.get("bus_loginer.config"),
			keys: ["bg_imgs", "using_bg_img", "is_bg_img_blur","is_use_bg_img","is_bg_img_alpha"]
		}, function(result) {
			var bus_info = result.result;
			App.set("bus_loginer", bus_info);
			bg_imgs = App.get("bus_loginer.config.bg_imgs");
			App.set("bus_info.config.using_bg_img", bus_info.config.using_bg_img);
			App.set("bus_info.config.is_bg_img_blur", bus_info.config.is_bg_img_blur);
			App.set("bus_info.config.is_bg_img_blur", bus_info.config.is_bg_img_alpha);
			cb && cb();
		}, function(errorCode, xhr, errorMsg) {
			alert("error", errorMsg);
		});
	}

	App.set("$Event.themeimg.show_upload_image", function(img_url) {
		console.log(App.get("$Cache.themeimg.preview_img_url"));
		bg_imgs.unshift({
			img_url: img_url,
			checked: false
		});
		_upload_config(function() {
			alert("success", "上传成功")
		});
	});
	App.set("$Event.themeimg.upload_config", function() {
		_upload_config(function() {
			alert("success", "修改成功")
		});
	});
	App.set("$Event.themeimg.remove_home_image", function(e, vm) {
		vm.remove();
		_upload_config(function() {
			alert("success", "删除成功")
		});
	});
});